import { observable, action } from 'mobx';
import * as API_AUTHOR from '../apis/docofauthor';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

export class DocOfAuthorStore {
  @observable title = getLabel(132041, '著者文档数量');
  @observable loading = false;
  @observable conditions = [];
  @observable reportPeopleData= [];
  @observable createDocNum = [];
  @observable mostDocCategory = [];
  @observable reportData = [];
  @observable reportTitle = '';
  @observable subdepartment = '';
  @observable department = '';
  @observable loadingChart = true;
  @observable loadingRPD = true;
  @observable loadingCDM = true;
  @observable loadingMDC = true;
  @observable prePath = '';
  @observable prePathName = '';
  constructor() {
    this.setTitle = this.setTitle.bind(this);
    this.setLoading = this.setLoading.bind(this);
    this.getCondition = this.getCondition.bind(this);
    this.getReportPeopleData = this.getReportPeopleData.bind(this);
    this.getCreateDocNum = this.getCreateDocNum.bind(this);
    this.getMostDocCategory = this.getMostDocCategory.bind(this);
    this.getReportData = this.getReportData.bind(this);
  }

  @action
  setTitle(title) {
    this.title = title;
  }
  setLoading(loading) {
    this.loading = loading;
  }
  setState = (params = {}) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
    return this;
  }
  getCondition(params = {}, query) {
  	if (JSON.stringify(query) !== '{}') {
  		if (query.deptType) params.deptType = query.deptType;
  		if (query.branch_id) params.branch_id = query.branch_id;
  		if (query.dept_id) params.dept_id = query.dept_id;
     }
    API_AUTHOR.getCondition(params).then((data) => {
      this.conditions = data.conditions;
    });
  }
  getReportPeopleData(params = {}) {
    this.loadingRPD = true;
    API_AUTHOR.getReportPeopleData(params).then((data) => {
      this.reportPeopleData = data;
      this.loadingRPD = false;
    });
  }
  getCreateDocNum(params = {}) {
    this.loadingCDM = true;
    API_AUTHOR.getCreateDocNum(params).then((data) => {
      this.createDocNum = data;
      this.loadingCDM = false;
    });
  }
  getMostDocCategory(params = {}) {
    this.loadingMDC = true;
    API_AUTHOR.getMostDocCategory(params).then((data) => {
      this.mostDocCategory = data;
      this.loadingMDC = false;
    });
  }
  getReportData(params = {}) {
    this.loadingChart = true;
    API_AUTHOR.getReportData(params).then((data) => {
      this.reportData = data.datas;
      this.reportTitle = data.show;
      this.loadingChart = false;
    });
  }
}
